class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0;
        int right = 0;
        int sum = nums[right];
        int count = INT_MAX;
        while (right < nums.size())
        {
            if (sum >= target)
            {
                count = min(count, right - left + 1);
                sum -= nums[left++];
                continue;
            }
            right++;
            if (right == nums.size()) break;
            sum += nums[right];
        }
        return count == INT_MAX ? 0 : count;
    }
};